package com.test.common;

import java.io.Serializable;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import msg.chestionar.ejb.bi.ChestionarBI;

import com.msg.chestionar.to.ChestionarTO;

@ManagedBean(name = "adaugaBean")
@SessionScoped
public class AdaugaBean implements Serializable {
	private static final long serialVersionUID = -4759076671753497857L;
	private long id;
	private String name;
	private String creat_de;
	private int activ;

	@EJB
	private ChestionarBI chestionarBI;

	public long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getCreat_de() {
		return creat_de;
	}

	public int getActiv() {
		return activ;
	}

	public void setId(long id) {
		this.id = id;
	}

	public void setName(String nume) {
		this.name = nume;
	}

	public void setCreate_de(String c) {
		this.creat_de = c;
	}

	public void setActiv(int a) {
		this.activ = a;
	}

	public String add_intrebare() {

		ChestionarTO ch = chestionarBI.getChestionar(this.id);
		if (ch == null) {
			FacesMessage msg = new FacesMessage("Adaugare esuata",
					"Chestionar inexistent");
			msg.setSeverity(FacesMessage.SEVERITY_ERROR);
			FacesContext.getCurrentInstance().addMessage(null, msg);
			return null;
		}
		return "adauga_intrebare";

	}

	public void save() {
		if (this.name == null) {
			FacesMessage msg = new FacesMessage("Incercare esuata",
					"Introduceti titlu chestionar");
			msg.setSeverity(FacesMessage.SEVERITY_ERROR);
			FacesContext.getCurrentInstance().addMessage(null, msg);
		}
		System.out.println("ID: " + this.id);
		System.out.println("Name: " + this.name);
		System.out.println("Activ: " + this.activ);
		//chestionarBI.addChestionar(this.name, "admin", this.activ);
	}

	public String end() {
		return "chestionar_adaugat";
	}
}
